package com.allwees.bs.module.scm.rest;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.allwees.bs.core.modelbase.vo.R;
import com.allwees.bs.module.core.dynamic.annotation.DynamicInject;
import com.allwees.bs.module.core.rest.BoCrudApi;
import com.allwees.bs.module.scm.entity.ScmShippingOrder;
import com.allwees.bs.module.scm.entity.ScmShippingOrderSku;
import com.allwees.bs.module.scm.req.EnteredWarehouseReq;
import com.allwees.bs.module.scm.req.query.ScmShippingOrderQueryReq;
import com.allwees.bs.module.scm.service.ScmShippingOrderService;
import com.allwees.bs.module.scm.service.ScmShippingOrderSkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/backstage/api/scm/shipping_order")
public class ScmShippingOrderApi extends BoCrudApi<ScmShippingOrder, ScmShippingOrderService> {

    @Autowired
    private ScmShippingOrderSkuService shippingOrderSkuService;

    @GetMapping("/page")
    public R page(Page<ScmShippingOrder> page, ScmShippingOrderQueryReq req) {
        return super.page(page, req);
    }

    @DynamicInject(key = "orderItemUuid")
    @GetMapping("/skus/{uuid}")
    public R skus(@PathVariable String uuid) {
        List<ScmShippingOrderSku> orderSkus = shippingOrderSkuService.findOrderSkus(uuid);
        return R.ok(orderSkus);
    }

    @GetMapping("/sku/{uuid}/refund_reason")
    public R refundReason(@PathVariable String uuid) {
        shippingOrderSkuService.refundReason(uuid);
        return R.ok();
    }

    @GetMapping("/sku/{uuid}/print")
    public R print(@PathVariable String uuid) {
        shippingOrderSkuService.print(uuid);
        return R.ok();
    }

    @PostMapping("/skus/entered_warehouse")
    public R enteredWarehouse(@RequestBody EnteredWarehouseReq req) {
        boService.enteredWarehouse(req);
        return R.ok();
    }
}
